/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.fatec.ads.classes;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author Ubirajara
 */
@Entity
public class Acesso extends AbstractTO {

    private int codigoAcesso;
    private Timestamp dataAcesso;
    private Cartao cartao;
    private Sala sala;
    private boolean autorizacaoEntrada;

    public Acesso() {
    }

    /**
     * @return the codigoAcesso
     */
    @Id
    @Column(name="cd_acesso", length=5)
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    public int getCodigoAcesso() {
        return codigoAcesso;
    }

    /**
     * @param codigoAcesso the codigoAcesso to set
     */
    public void setCodigoAcesso(int codigoAcesso) {
        this.codigoAcesso = codigoAcesso;
    }

    /**
     * @return the dataAcesso
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="dt_acesso", nullable=false)
    public Date getDataAcesso() {
        return dataAcesso;
    }

    /**
     * @param dataAcesso the dataAcesso to set
     */
    public void setDataAcesso(Timestamp dataAcesso) {
        this.dataAcesso = dataAcesso;
    }

    /**
     * @return the cartao
     */
    @ManyToOne(fetch=FetchType.LAZY)
    @Fetch(FetchMode.SELECT)
    @JoinColumn(name="cd_cartao", referencedColumnName="cd_cartao", nullable=false)
    public Cartao getCartao() {
        return cartao;
    }

    /**
     * @param cartao the cartao to set
     */
    public void setCartao(Cartao cartao) {
        this.cartao = cartao;
    }

    /**
     * @return the sala
     */
    @ManyToOne(fetch=FetchType.LAZY)
    @Fetch(FetchMode.SELECT)
    @JoinColumns(value={@JoinColumn(name="cd_sequencial", referencedColumnName="cd_sequencial", nullable=false),
                        @JoinColumn(name="tp_local", referencedColumnName="tp_local", nullable=false)})
    public Sala getSala() {
        return sala;
    }

    /**
     * @param sala the sala to set
     */
    public void setSala(Sala sala) {
        this.sala = sala;
    }

    /**
     * @return the autorizacaoEntrada
     */
    @Column(name="ic_acesso", nullable=false, length=1)
    public boolean isAutorizacaoEntrada() {
        return autorizacaoEntrada;
    }

    /**
     * @param autorizacaoEntrada the autorizacaoEntrada to set
     */
    public void setAutorizacaoEntrada(boolean autorizacaoEntrada) {
        this.autorizacaoEntrada = autorizacaoEntrada;
    }


    @Transient
    @Override
    public Serializable getPK() {
        return this.getCodigoAcesso();
    }

    @Override
    public void setPK(Serializable identifier) {
        this.setCodigoAcesso((Integer) identifier);
    }

    @Override
    public String toString() {
        return "Acesso[codigo=" + this.getCodigoAcesso() +
                    ", dataAcesso=" + this.getDataAcesso() +
                    ", cartao=" + this.getCartao().getCodigo() +
                    ", sala=" + this.getSala().getCodigo() +
                    ", autorizacaoEntrada=" + this.isAutorizacaoEntrada() + "]";
    }

}
